/*
 * 文件名：OrderByInfoServiceImp.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：ozm
 * 修改时间：2013-1-28
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.reservation.bookinfo.service.imp;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import javax.servlet.http.HttpServletRequest;
import org.springframework.dao.DataAccessException;
import com.wootide.cms.common.CMSRuntimeException;
import com.wootide.cms.common.Constants;
import com.wootide.cms.common.ErrorCodes;
import com.wootide.cms.common.Page;
import com.wootide.cms.common.QueryCondition;
import com.wootide.cms.common.QueryResults;
import com.wootide.cms.common.Result;
import com.wootide.cms.common.util.CommonUtil;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.customer.custmanager.dao.CustManagerDao;
import com.wootide.cms.service.customer.custmanager.pojo.Customer;
import com.wootide.cms.service.facility.room.roominfo.dao.RoomInfoDao;
import com.wootide.cms.service.facility.room.roominfo.pojo.RoomInfo;
import com.wootide.cms.service.facility.room.roominfo.pojo.RoomPeriod;
import com.wootide.cms.service.facility.room.table.pojo.TableNoInfo;
import com.wootide.cms.service.facility.room.table.pojo.TablePeriod;
import com.wootide.cms.service.reservation.bookinfo.dao.BookOrderInfoDao;
import com.wootide.cms.service.reservation.bookinfo.pojo.BookOrderInfo;
import com.wootide.cms.service.reservation.bookinfo.service.BookOrderInfoService;
import com.wootide.cms.service.reservation.bookinfo.transaction.BookOrderInfoTransaction;
import com.wootide.cms.service.reservation.orderby.dao.OrderByInfoDao;
import com.wootide.cms.service.reservation.orderby.pojo.OrderByInfo;
import com.wootide.cms.service.reservation.orderby.service.OrderByInfoService;
import com.wootide.cms.service.reservation.orderby.transaction.OrderByInfoTransaction;

/**
 * 预订方式业务层实现层
 * 〈一句话功能简述〉
 * 〈功能详细描述〉
 * @author ozm
 * @version 2013-1-28
 * @see BookOrderInfoServiceImp
 * @since 2013-1-28下午2:20:01
 */
public class BookOrderInfoServiceImp implements BookOrderInfoService
{
    // 注入运行日志
    private RunLog runLog;
    
    //事物层实例
    private BookOrderInfoTransaction bookOrderInfoTransaction;
    
    //数据访问层实例
    private BookOrderInfoDao bookOrderInfoDao;
    
//    //房间数据访问层
//    private RoomInfoDao roomInfoDao;
    //客户信息数据访问层
    private CustManagerDao custManagerDao;
    
   

  
    /**
     * 
     * Description: 分页查询
     * Implement: <br>
     * @param page 分页参数
     * @param queryConditon 查询条件
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午1:23:32
     */
    public Result queryForPages(Page page, QueryCondition queryConditon)
    {
        // 打印方法入口参数
        runLog.debug("page=" + page);
        runLog.debug("queryConditon=" + queryConditon);
        
        // 定义返回结果
        Result result = new Result();
        try
        {
            queryConditon = null == queryConditon? new QueryCondition() : queryConditon;
            queryConditon.setObjClass(BookOrderInfo.class);
            QueryResults queryResults = bookOrderInfoTransaction.queryForPages(page,
                    queryConditon);
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query BookOrderInfo Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query BookOrderInfo Failed!", e);
            // 注册修改前的路由对象
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query BookOrderInfo Failed!", e);
            // 注册修改前的路由对象
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    
    /**
     * 
     * Description: 添加一条客户预订信息
     * Implement: <br>
     * @param queryConditon 要添加的客户预订信息
     * @param request HttpServletRequest
     * @return
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午1:26:06
     */
    public Result addOneBookOrder(QueryCondition queryConditon,HttpServletRequest request)
    {
        // 打印方法入口参数
        runLog.debug("queryConditon=" + queryConditon);
        Result result = new Result();
        try
        {
            bookOrderInfoTransaction.addOneBookOrder(queryConditon);
//            bookOrderInfoTransaction.bulidingPerioid(queryConditon);
            runLog.info("Add BookOrderInfo Success! Input data:" + queryConditon, request);
            
            // 设置返回码为成功
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Add BookOrderInfo Failed! Input data:" + queryConditon, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        catch (CMSRuntimeException e)
        {
            //运行时异常
            runLog.info("Add BookOrderInfo Failed! Input Data:" + queryConditon
                    + " Error Message:" + e.getMessage(), request);
            
            result.setResultCode(e.getErrorCode());
        }
        catch (Exception e)
        {
            //未知异常
            runLog.error("Add BookOrderInfo Failed!Input data:" + queryConditon, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    
    /**
     * 
     * Description: 修改一条客户预订信息
     * Implement: <br>
     * @param bookOrderInfo 要修点的客户预订信息
     * @param request HttpServletRequest
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午1:27:37
     */
    public Result modOneBookOrder(BookOrderInfo bookOrderInfo,HttpServletRequest request)
    {
        // 打印方法入口参数
        runLog.debug("bookOrderInfo=" + bookOrderInfo);
        Result result = new Result();
        try
        {
            BookOrderInfo oldBookOrderInfo = bookOrderInfoTransaction.modOneBookOrder(bookOrderInfo);
            runLog.info("Mod BookOrderInfo Success! Input data:" + bookOrderInfo
                    + "|oldDate:" + oldBookOrderInfo, request);
            
            // 设置返回码为成功
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Mod BookOrderInfo Failed! Input data:" + bookOrderInfo, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        catch (CMSRuntimeException e)
        {
            //自定义异常
            runLog.info("Mod BookOrderInfo Failed! Input Data:" + bookOrderInfo
                    + " Error Message:" + e.getMessage(), request);
            result.setResultCode(e.getErrorCode());
        }
        catch (Exception e)
        {
            //位置异常
            runLog.error("Mod BookOrderInfo Failed!Input data:" + bookOrderInfo, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    
    /**
     * 修改一房间的时段信息
     * Description: <br>
     * Implement: <br>
     * @param bookOrderInfo 订单信息
     * @param innerIndexs 修改后的时段索引
     * @param request 
     * @return
     * @see
     * @return Result 结果集
     * @author ozm2013-4-12下午5:31:59
     */
    public Result modOneOrderRoomPeriod(BookOrderInfo bookOrderInfo,
            Integer[] innerIndexs, HttpServletRequest request)
    {
        // 打印方法入口参数
        runLog.debug("bookOrderInfo=" + bookOrderInfo);
        Result result = new Result();
        try
        {
            BookOrderInfo oldBookOrderInfo = bookOrderInfoTransaction.modOneOrderRoomPeriod(bookOrderInfo,innerIndexs);
            runLog.info("Mod modOneOrderRoomPeriod Success! Input data:" + bookOrderInfo
                    + "|oldDate:" + oldBookOrderInfo, request);
            runLog.info("Mod modOneOrderRoomPeriod Success! Input data:" + innerIndexs, request);
            // 设置返回码为成功
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Mod BookOrderInfo Failed! Input data:" + bookOrderInfo, e, request);
            runLog.error("Mod modOneOrderRoomPeriod Success! Input data:" + innerIndexs,e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        catch (CMSRuntimeException e)
        {
            //自定义异常
            runLog.info("Mod BookOrderInfo Failed! Input Data:" + bookOrderInfo
                    + " Error Message:" + e.getMessage(), request);
            runLog.info("Mod modOneOrderRoomPeriod Success! Input data:" + innerIndexs, request);
            result.setResultCode(e.getErrorCode());
        }
        catch (Exception e)
        {
            //位置异常
            runLog.error("Mod BookOrderInfo Failed!Input data:" + bookOrderInfo, e, request);
            runLog.error("Mod modOneOrderRoomPeriod Success! Input data:" + innerIndexs,e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    
    
    /**
     * 修改一桌次的时段信息
     * Description: <br>
     * Implement: <br>
     * @param bookOrderInfo 订单信息
     * @param innerIndexs 修改后的时段索引
     * @param request 
     * @return
     * @see
     * @return Result 结果集
     * @author ozm2013-4-12下午5:31:59
     */
    public Result modOneOrderTablePeriod(BookOrderInfo bookOrderInfo,
            Integer[] innerIndexs, HttpServletRequest request)
    {
        
        // 打印方法入口参数
        runLog.debug("bookOrderInfo=" + bookOrderInfo);
        Result result = new Result();
        try
        {
            BookOrderInfo oldBookOrderInfo = bookOrderInfoTransaction.modOneOrderRoomPeriod(bookOrderInfo,innerIndexs);
            runLog.info("Mod modOneOrderTablePeriod Success! Input data:" + bookOrderInfo
                    + "|oldDate:" + oldBookOrderInfo, request);
            runLog.info("Mod modOneOrderTablePeriod Success! Input data:" + innerIndexs, request);
            // 设置返回码为成功
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Mod BookOrderInfo Failed! Input data:" + bookOrderInfo, e, request);
            runLog.error("Mod modOneOrderTablePeriod Success! Input data:" + innerIndexs,e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        catch (CMSRuntimeException e)
        {
            //自定义异常
            runLog.info("Mod BookOrderInfo Failed! Input Data:" + bookOrderInfo
                    + " Error Message:" + e.getMessage(), request);
            runLog.info("Mod modOneOrderTablePeriod Success! Input data:" + innerIndexs, request);
            result.setResultCode(e.getErrorCode());
        }
        catch (Exception e)
        {
            //位置异常
            runLog.error("Mod BookOrderInfo Failed!Input data:" + bookOrderInfo, e, request);
            runLog.error("Mod modOneOrderTablePeriod Success! Input data:" + innerIndexs,e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }

    
    
    /**
     * 
     * Description: 通过索引查询一条客户预订信息
     * Implement: <br>
     * @param innerIndex 要查询一条客户预订信息的Id
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午3:55:17
     */
    @SuppressWarnings("unchecked")
    public Result viewOneBookOrder(Integer innerIndex)
    {

        // 打印方法入口参数
        runLog.debug("innerIndex=" + innerIndex);

        Result result = new Result();
        try
        {
            QueryResults queryResults = bookOrderInfoTransaction.viewOneBookOrder(innerIndex);
            
            
            List<RoomInfo> roomList = (List<RoomInfo>)queryResults.getResults().get(2);
            
            BookOrderInfo bookOrderInfo = (BookOrderInfo)queryResults.getResults().get(3);
            //设置价格
            if (roomList.size() > 0)
            {
                setOrderPrice(bookOrderInfo,roomList);
            }
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            result.setResultPojo(queryResults);
        }
        catch (DataAccessException e)
        {
            runLog.error("Find One BookOrderInfo Failed!", e);
            // 注册修改前的中文路由对象
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        catch (CMSRuntimeException e)
        {
            //自定义异常
            runLog.info("Mod BookOrderInfo Failed! Input Data:" + innerIndex
                    + " Error Message:" + e.getMessage());
            result.setResultCode(e.getErrorCode());
        }
        catch (Exception e)
        {
            runLog.error("Find One BookOrderInfo Failed!", e);
            // 注册修改前的中文路由对象
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    
    }
    
    /**
     * 
     * Description: 删除客户预订信息
     * Implement: <br>
     * @param innerIndexs 要删除的客户预订信息id列表
     * @param request HttpServletRequest
     * @return
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午4:17:56
     */
    public Result delBookOrders(Integer[] innerIndexs, HttpServletRequest request)
    {
        // 打印方法入口参数
        runLog.debug("innerIndexs = " + CommonUtil.toString(innerIndexs));
        
        Result result = new Result();
        
        result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
        // 定义删除失败的条数
        int delErrorNum = 0;
        
        for (Integer innerIndex : innerIndexs)
        {
            BookOrderInfo bookOrderInfo = null;
            try
            {
                // 调用删除路由事务层
                bookOrderInfo = bookOrderInfoTransaction.delOneBookOrder(innerIndex);
                runLog.info("Delete BookOrderInfo Success! bookOrderInfo = " + bookOrderInfo,
                        request);
                
            }
            catch (DataAccessException e)
            {
                //数据库异常
                delErrorNum++;
                runLog.error("Delete BookOrderInfo Failed! Innerindex = " + innerIndex,
                        e,
                        request);
                
                result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
                
            }
            catch (CMSRuntimeException e)
            {
                //运行时异常
                runLog.info("Delete BookOrderInfo Failed! Innerindex = " + innerIndex
                        + " Error Message:" + e.getMessage(), request);
                result.setResultCode(e.getErrorCode());
                
            }
            catch (Exception e)
            {
                //未知异常
                delErrorNum++;
                runLog.error("Delete BookOrderInfo Failed!  Innerindex = " + innerIndex,
                        e,request);
                result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
                
            }
        }
        // 返回失败的条数
        result.setDelErrorNum(delErrorNum);
        return result;
    }
    
    /**
     * 取消已经预订的时段
     * Description: <br>
     * Implement: <br>
     * @param queryConditon 条件
     * @param request 
     * @return
     * @see
     * @return Result 结果集
     * @author ozm2013-4-16下午1:20:54
     */
    public Result delOrderPeriods(QueryCondition queryConditon,
            HttpServletRequest request)
    {
        // 打印方法入口参数
        runLog.debug("queryConditon=" + queryConditon);
        Result result = new Result();
        try
        {
            bookOrderInfoTransaction.delOrderPeriods(queryConditon);
//            bookOrderInfoTransaction.bulidingPerioid(queryConditon);
            runLog.info("Delete OrderPeriods Success! Input data:" + queryConditon, request);
            
            // 设置返回码为成功
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Delete delOrderPeriods Failed! Input data:" + queryConditon, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        catch (CMSRuntimeException e)
        {
            //运行时异常
            runLog.info("Delete delOrderPeriods Failed! Input Data:" + queryConditon
                    + " Error Message:" + e.getMessage(), request);
            
            result.setResultCode(e.getErrorCode());
        }
        catch (Exception e)
        {
            //未知异常
            runLog.error("Delete delOrderPeriods Failed!Input data:" + queryConditon, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }

    /**
   /**
     * 
     * Description: 新增一条客户预订信息唯一性验证
     * Implement: <br>
     * @param content 客户预订信息名称
     * @return
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-31下午1:41:22
     */
    public Result checkContentWhenAdd(BookOrderInfo bookOrderInfo)
    {
        
        // 打印方法入口参数
        runLog.debug("bookOrderInfo=" + bookOrderInfo);
        Customer customerInfo = new Customer();
        customerInfo.setCustName(bookOrderInfo.getCustomerName());
        customerInfo.setTel(bookOrderInfo.getTel());
        Customer oldCustomerInfo = custManagerDao.findOneCustomerByNameAndPhoneOrCardNo(customerInfo);
        Result result = new Result();
        // 如果是客户
        if (null != oldCustomerInfo)
        {
            runLog.info("Legal!It is an Customer ! Input Data:" + bookOrderInfo);
            result.setResultPojo(oldCustomerInfo);
           
        }
        // 如果不是客户
        else
        {
            runLog.info("Illegal!It is not an Customer ! Input Data:" + bookOrderInfo);
           
        }
        
        result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
        return result;
    }
    
    
  

 
//    /**
//     * 检查是否有空闲接待室
//     * Description: <br>
//     * Implement: <br>
//     * @see
//     * @return void
//     * @author ozm2013-3-13下午4:46:22
//     */
//    private void checkHasIdleAnteroom()
//    {
//        
//    }
    
    /**
     * 查询可预订房间时段信息
     * Description: <br>
     * Implement: <br>
     * @param queryConditon 查询条件
     * @return
     * @see
     * @return Result
     * @author ozm2013-3-15下午2:03:01
     */
    public Result queryBookableRoomPeriod(QueryCondition queryConditon)
    {
        runLog.debug("queryConditon=" + queryConditon);
        
        // 定义返回结果
        Result result = new Result();
       
        
        try
        {
            QueryResults queryResults =  bookOrderInfoTransaction.queryBookableRoomPeriod(queryConditon);;
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query BookableRoomPeriod Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query BookableRoomPeriod Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query BookableRoomPeriod Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
       
    }
    
    /**
     * 查询可预订房间数
     * Description: <br>
     * Implement: <br>
     * @param queryConditon 查询条件
     * @return
     * @see
     * @return Result
     * @author ozm2013-3-18下午2:49:17
     */
    public Result queryBookableRooms(QueryCondition queryConditon)
    {
        runLog.debug("queryConditon=" + queryConditon);
        // 定义返回结果
        Result result = new Result();
        try
        {
            QueryResults queryResults = bookOrderInfoTransaction.queryBookableRooms(queryConditon);
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query BookableRoom Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query BookableRoom Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query BookableRoom Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    
    
    
    /**
     * 查询可预订桌次信息
     * Description: <br>
     * Implement: <br>
     * @param queryConditon 查询条件
     * @return
     * @see
     * @return Result 结果集
     * @author ozm2013-3-15下午2:03:01
     */
    public Result queryBookableTableNos(QueryCondition queryConditon)
    {
        runLog.debug("queryConditon=" + queryConditon);
        // 定义返回结果
        Result result = new Result();
        try
        {
            QueryResults queryResults = bookOrderInfoTransaction.queryBookableTableNos(queryConditon);
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query BookableTableNos Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query BookableTableNos Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query BookableTableNos Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    
    /**
     * 查询可预订桌次时段
     * Description: <br>
     * Implement: <br>
     * @param queryConditon 查询条件
     * @return
     * @see
     * @return Result 结果集
     * @author ozm2013-3-15下午2:03:01
     */
    public Result queryBookableTablePeriods(QueryCondition queryConditon)
    {
        runLog.debug("queryConditon=" + queryConditon);
        
        // 定义返回结果
        Result result = new Result();
        
        try
        {
            QueryResults queryResults =  bookOrderInfoTransaction.queryBookableTablePeriods(queryConditon);
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query BookableTablePeriods Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query BookableTablePeriods Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query BookableTablePeriods Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    

    /**
     * 查询所有预订方式和支付方式
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return Result
     * @author ozm2013-3-26下午6:39:15
     */
    @SuppressWarnings("unchecked")
    public Result queryBookingPreviewInfo(QueryCondition queryConditon)
    {
        
        // 定义返回结果
        Result result = new Result();
        
        try
        {
            QueryResults queryResults =  bookOrderInfoTransaction.queryBookingPreviewInfo(queryConditon);
            
            List<RoomInfo> roomList = (List<RoomInfo>)queryResults.getResults().get(2);
           
            BookOrderInfo bookOrderInfo = (BookOrderInfo)queryResults.getResults().get(3);
            
            setOrderPrice(bookOrderInfo, roomList);
//            //订单原价总价
//            double orderOriginalTotalPrice = 0;
//            Customer oldCustomerInfo = bookOrderInfo.getCustomerInfo();
//           
//             //计算折扣价
//            for (RoomInfo roomInfo : roomList)
//            {
//                
//                if(Constants.RooomType.CHABA.equals(roomInfo.getRoomTypeInfo().getRoomTypeId()) 
//                        ||Constants.RooomType.CHESS_ROOM.equals(roomInfo.getRoomTypeInfo().getRoomTypeId()))
//                {
//                    // 棋牌室或者茶吧
//                   
//                    Set<TableNoInfo> tableNoInfoSet = roomInfo.getTableNoInfos();
//                    
//                    for(TableNoInfo tableNoInfo : tableNoInfoSet)
//                    {
//                        //计算桌次定折后价
//                        if (null != oldCustomerInfo)
//                        {
//                            tableNoInfo.setDiscountPrice(tableNoInfo.getOriginalPricePerTable() * oldCustomerInfo.getClientLevelId().getDiscount());
//                           
//                        }
//                        //获取时段字符串
//                        tableNoInfo.setPeriodStr(CommonUtil.getPeriodsStr(tableNoInfo.getTablePeriods(),Constants.PeriodType.TABLE_PERIOD));
//                        
//                    }
//
//                    calculateRoomPrice(roomInfo, tableNoInfoSet);
//                }
//                else
//                {
//                    //获取时段字符串
//                    roomInfo.setPeriodStr(CommonUtil.getPeriodsStr(roomInfo.getRoomPeriods(),Constants.PeriodType.ROOM_PERIOD));    
//                }
//                
//                //其他类型房间
//                if (null != oldCustomerInfo.getClientLevelId())
//                {
//                    roomInfo.setDiscountPrice(roomInfo.getOriginalPricePerRoom() * oldCustomerInfo.getClientLevelId().getDiscount());
//                }
//               
//                
//                orderOriginalTotalPrice = orderOriginalTotalPrice + roomInfo.getOriginalPricePerRoom();        
//            }
//            
//            //订单折扣前价格
//            bookOrderInfo.setOriginalPricePerRoom(orderOriginalTotalPrice);
//            
//            if (null != oldCustomerInfo.getClientLevelId())
//            {
//                bookOrderInfo.setRoomTotalPrice(orderOriginalTotalPrice * oldCustomerInfo.getClientLevelId().getDiscount());
//            }
//            else
//            {
//                bookOrderInfo.setRoomTotalPrice(orderOriginalTotalPrice);
//            }
           
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query queryBookingPreviewInfo Success!");
        }
            
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query queryBookingPreviewInfo Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query queryBookingPreviewInfo Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }

    
    
    /**
     * 获取预订方式和支付方式
     * Description: <br>
     * Implement: <br>
     * @return
     * @see
     * @return Result 结果集
     * @author ozm2013-3-28下午7:49:49
     */
    public Result queryBookableOrderBysAndPayments()
    {
        runLog.debug("queryBookableOrderBysAndPayments");
        // 定义返回结果
        Result result = new Result();
        
        try
        {
            QueryResults queryResults =  bookOrderInfoTransaction.queryBookableOrderBysAndPayments();
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query queryBookableOrderBysAndPayments Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query queryBookableOrderBysAndPayments Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query queryBookableOrderBysAndPayments Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        
        return result;
    }

    /**
     * 查询订单预览时间段信息
     * Description: <br>
     * Implement: <br>
     * @param queryConditon
     * @return
     * @see
     * @return Result
     * @author ozm2013-3-30下午11:48:18
     */
    public Result queryPreviewPeriods(QueryCondition queryConditon)
    {
        runLog.debug("queryConditon=" + queryConditon);
        // 定义返回结果
        Result result = new Result();
        
        try
        {
            QueryResults queryResults =  bookOrderInfoTransaction.queryPreviewPeriods(queryConditon);
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query queryPreviewPeriods Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query queryPreviewPeriods Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query queryPreviewPeriods Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        
        return result;
    }
    
    /**
     * 通过所以获取房间预订时段
     * Description: <br>
     * Implement: <br>
     * @param roomId 房间索引和订单索引
     * @return
     * @see
     * @return Result 房间时段结果集
     * @author ozm2013-4-10下午2:07:44
     */
    public Result queryOrderRoomPeriods(QueryCondition queryConditon)
    {
        runLog.debug("queryConditon=" + queryConditon);
        
        // 定义返回结果
        Result result = new Result();
        
        try
        {
            QueryResults queryResults =  bookOrderInfoTransaction.queryOrderRoomPeriods(queryConditon);
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query queryOrderRoomPeriods Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query queryOrderRoomPeriods Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query queryOrderRoomPeriods Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        
        return result;
    }
    
    /**
     * 通过索引获取桌次预订时段
     * Description: <br>
     * Implement: <br>
     * @param queryConditon 桌次索引和订单索引
     * @return
     * @see
     * @return Result 桌次时段结果集
     * @author ozm2013-4-10下午2:07:44
     */
    public Result queryOrderTablePeriods(QueryCondition queryConditon)
    {
        runLog.debug("queryConditon=" + queryConditon);
        
        // 定义返回结果
        Result result = new Result();
        
        try
        {
            QueryResults queryResults =  bookOrderInfoTransaction.queryOrderTablePeriods(queryConditon);
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query queryOrderTablePeriods Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query queryOrderTablePeriods Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query queryOrderTablePeriods Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        
        return result;
    }


    
    /**
     * 通过索引获取房间预订时段
     * Description: <br>
     * Implement: <br>
     * @param queryConditon 房间索引和订单索引
     * @return
     * @see
     * @return Result 房间时段结果集
     * @author ozm2013-4-10下午2:07:44
     */
    public Result queryPeriods(QueryCondition queryConditon)
    {
        runLog.debug("queryConditon=" + queryConditon);
        
        // 定义返回结果
        Result result = new Result();
        
        try
        {
            QueryResults queryResults =  bookOrderInfoTransaction.queryPeriods(queryConditon);
            
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query queryOrderRoomPeriods Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query queryOrderRoomPeriods Failed!", e);
            
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query queryOrderRoomPeriods Failed!", e);
           
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        
        return result;
    }
    
    /**
     * 设置订单价格
     * Description: <br>
     * Implement: <br>
     * @param bookOrderInfo  订单信息
     * @param roomList 房间列表
     * @see
     * @return void
     * @author ozm2013-4-9上午10:30:12
     */
    private void setOrderPrice(BookOrderInfo bookOrderInfo,List<RoomInfo> roomList)
    {
        //订单原价总价
        double orderOriginalTotalPrice = 0;
        Customer oldCustomerInfo = bookOrderInfo.getCustomerInfo();
       
         //计算折扣价
        for (RoomInfo roomInfo : roomList)
        {
            
            if(Constants.RooomType.CHABA.equals(roomInfo.getRoomTypeInfo().getRoomTypeId()) 
                    ||Constants.RooomType.CHESS_ROOM.equals(roomInfo.getRoomTypeInfo().getRoomTypeId()))
            {
                // 棋牌室或者茶吧
               
                Set<TableNoInfo> tableNoInfoSet = roomInfo.getTableNoInfos();
                
                for(TableNoInfo tableNoInfo : tableNoInfoSet)
                {
                    //计算桌次定折后价
                    if (null != oldCustomerInfo && null != oldCustomerInfo.getClientLevelId())
                    {
                        tableNoInfo.setDiscountPrice(tableNoInfo.getOriginalPricePerTable() * oldCustomerInfo.getClientLevelId().getDiscount());
                       
                    }
                    //获取时段字符串
                    tableNoInfo.setPeriodStr(CommonUtil.getPeriodsStr(tableNoInfo.getTablePeriods(),Constants.PeriodType.TABLE_PERIOD));
                    
                }

                calculateRoomPrice(roomInfo, tableNoInfoSet);
            }
            else
            {
                //获取时段字符串
                roomInfo.setPeriodStr(CommonUtil.getPeriodsStr(roomInfo.getRoomPeriods(),Constants.PeriodType.ROOM_PERIOD));    
            }
            
            //其他类型房间
            if (null !=oldCustomerInfo  && null != oldCustomerInfo.getClientLevelId())
            {
                roomInfo.setDiscountPrice(roomInfo.getOriginalPricePerRoom() * oldCustomerInfo.getClientLevelId().getDiscount());
            }
           
            
            orderOriginalTotalPrice = orderOriginalTotalPrice + roomInfo.getOriginalPricePerRoom();        
        }
        
        //订单折扣前价格
        bookOrderInfo.setOriginalPricePerRoom(orderOriginalTotalPrice);
        
        if (null !=oldCustomerInfo  && null != oldCustomerInfo.getClientLevelId())
        {
            bookOrderInfo.setRoomTotalPrice(orderOriginalTotalPrice * oldCustomerInfo.getClientLevelId().getDiscount());
        }
        else
        {
            bookOrderInfo.setRoomTotalPrice(orderOriginalTotalPrice);
        }
    }
    
    /**
     * 计算茶包和棋牌室房间原价总价和折后总价,同时更新桌号折扣价
     * Description: <br>
     * Implement: <br>
     * @param roomInfo
     * @param tableNoInfoList
     * @see
     * @return void
     * @author ozm2013-3-30上午10:54:28
     */
    private void calculateRoomPrice(RoomInfo roomInfo, Set<TableNoInfo> tableNoInfoList)
    {
        double totalOriginalPricePerRoom = 0;
        
        for (TableNoInfo tableNoInfo : tableNoInfoList)
        {
            totalOriginalPricePerRoom += tableNoInfo.getOriginalPricePerTable();
            
        }
        
        roomInfo.setOriginalPricePerRoom(totalOriginalPricePerRoom);
        
        
    }
    
   
   

   
    
    public RunLog getRunLog()
    {
        return runLog;
    }

    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }

    public BookOrderInfoTransaction getBookOrderInfoTransaction()
    {
        return bookOrderInfoTransaction;
    }

    public void setBookOrderInfoTransaction(
            BookOrderInfoTransaction bookOrderInfoTransaction)
    {
        this.bookOrderInfoTransaction = bookOrderInfoTransaction;
    }

    public BookOrderInfoDao getBookOrderInfoDao()
    {
        return bookOrderInfoDao;
    }

    public void setBookOrderInfoDao(BookOrderInfoDao bookOrderInfoDao)
    {
        this.bookOrderInfoDao = bookOrderInfoDao;
    }

    public CustManagerDao getCustManagerDao()
    {
        return custManagerDao;
    }

    public void setCustManagerDao(CustManagerDao custManagerDao)
    {
        this.custManagerDao = custManagerDao;
    }

    

    
   

     
   

  
}
